/*
 * @lc app=leetcode.cn id=1472 lang=golang
 * @lcpr version=30118
 *
 * [1472] 设计浏览器历史记录
 */

// @lcpr-template-start

// @lcpr-template-end

// @lc code=start

type Node struct {
	Url  string
	Prev *Node
	Next *Node
}

type BrowserHistory struct {
	Head *Node
	Curr *Node
}

func Constructor(homepage string) BrowserHistory {
	this := &BrowserHistory{&Node{}, nil}
	this.Head.Next = &Node{Url: homepage, Prev: this.Head}
	this.Curr = this.Head.Next
	return *this
}

func (this *BrowserHistory) Visit(url string) {
	this.Curr.Next = &Node{Url: url, Prev: this.Curr, Next: nil}
	this.Curr = this.Curr.Next
}

func (this *BrowserHistory) Back(steps int) string {
	for this.Curr.Prev != this.Head && steps > 0 {
		this.Curr = this.Curr.Prev
		steps--
	}
	return this.Curr.Url
}

func (this *BrowserHistory) Forward(steps int) string {
	for this.Curr.Next != nil && steps > 0 {
		this.Curr = this.Curr.Next
		steps--
	}
	return this.Curr.Url
}

/**
 * Your BrowserHistory object will be instantiated and called as such:
 * obj := Constructor(homepage);
 * obj.Visit(url);
 * param_2 := obj.Back(steps);
 * param_3 := obj.Forward(steps);
 */
// @lc code=end

/*
// @lcpr case=start
// ["BrowserHistory","visit","visit","visit","back","back","forward","visit","forward","back","back"][["leetcode.com"],["google.com"],["facebook.com"],["youtube.com"],[1],[1],[1],["linkedin.com"],[2],[2],[7]]\n
// @lcpr case=end

*/

